#include <iostream>
#include "c9_T4_sales.h"

namespace SALES
{
	using std::cout;
	using std::cin;
	using std::endl;

	void setSales(Sales & s, const  double ar[], int n)
	{
		s.max = s.min = ar[0];
		for (int i = 0; i < n && i<QUARTERS; i++)
		{
			static double total = 0;
			s.sales[i] = ar[i];
			total += s.sales[i];
			s.average = total / i;
			s.max = (s.sales[i]>s.max) ? s.sales[i] : s.max;
			s.min = (s.sales[i]<s.min) ? s.sales[i] : s.min;
		}
	}

	void setSales(Sales & s)
	{
		cout << "enter the sales of the quarters in order : " << endl;
		while (!(cin >> s.sales[0] >> s.sales[1] >> s.sales[2] >> s.sales[3]))
		{
			cin.clear();
			while (cin.get() != '\n')
				continue;
			cout << "bad input, enter the sales of the quarters in order : " << endl;
		}

		s.max = s.min = s.sales[0];
		for (int i = 0; i < QUARTERS; i++)
		{
			static double total = 0;
			total += s.sales[i];
			s.average = total / i;
			s.max = (s.sales[i]>s.max) ? s.sales[i] : s.max;
			s.min = (s.sales[i]<s.min) ? s.sales[i] : s.min;
		}
	}

	void showSales(const Sales & s)
	{
		cout << "sales of quarters : " << endl;
		for (int i = 0; i < QUARTERS; i++)
			cout << s.sales[i] << "  ";
		cout << "\navarage : " << s.average 
			<< " max : " << s.max << " min : " << s.min << endl;
	}
}